package com.ants.boot.utils;

import com.ants.boot.system.domain.SysLoginLog;
import com.ants.boot.system.service.SysLoginLogService;
import eu.bitwalker.useragentutils.UserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 蚂蚁会花呗
 * @date 2022/3/22 15:07
 */
public class LoginLogUtils {

    private static Logger logger = LoggerFactory.getLogger(LoginLogUtils.class);

    /**
     * 登录状态
     * @param request
     * @param sysLoginLogService
     */
    public static void addLoginLog(HttpServletRequest request, SysLoginLogService sysLoginLogService,String loginName, String loginStatus,String loginMsg){
        UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("user-agent"));
        String os = userAgent.getOperatingSystem().getName();
        String ip = IpUtils.getIpAddress(request);
        String browser = userAgent.getBrowser().toString();
        SysLoginLog log = new SysLoginLog(loginName,ip,"暂无开发",browser,os,loginStatus,loginMsg);
        sysLoginLogService.addSysLoginLog(log);
        logger.info("登录日志保存成功");
    }

}
